<template>
  <div class="subsidy">
    <div class="subsidy-header">领取补贴金额</div>

    <div class="subsidy-block">
      <div class="list" v-for="(item, index) in subsidyList" :key="index">
        <div class="title">
          {{
            index == 0
              ? "早餐"
              : index == 1
              ? "午餐"
              : index == 2
              ? "晚餐"
              : index == 3
              ? "夜宵"
              : ""
          }}
        </div>

        <div class="time">
          <el-time-select
            v-model="item.startTime"
            :picker-options="{
              start: '00:00',
              end: '24:00',
            }"
            placeholder="选择时间"
            value-format="HH:mm:ss"
          >
          </el-time-select>
          -
          <el-time-select
            v-model="item.finishTime"
            :picker-options="{
              start: '00:00',
              end: '24:00',
            }"
            placeholder="选择时间"
            value-format="HH:mm:ss"
          >
          </el-time-select>
        </div>

        <div class="price">
          <el-input v-model="item.integral" placeholder="请输入积分"></el-input>
          <div class="integral">积分</div>
        </div>

        <div class="button">
          <div class="title" @click="welfareChowtimeListAddMet(item)">保存</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { welfareChowtimeList, welfareChowtimeListAdd } from "@/api/welfare";

export default {
  data() {
    return {
      //----------------
      subsidyList: [],
    };
  },
  created() {
    this.welfareChowtimeListMet();
  },
  methods: {
    welfareChowtimeListMet() {
      let params = {};

      welfareChowtimeList(params).then((res) => {
        if (res.errorCode == null) {
          res.resultData.forEach((item, index) => {
            item.startTime =
              ((item.startHour + "").length == 1
                ? "0" + "" + item.startHour
                : item.startHour) +
              ":" +
              ((item.startMinute + "").length == 1
                ? "0" + "" + item.startMinute
                : item.startMinute);

            item.finishTime =
              ((item.endHour + "").length == 1
                ? "0" + "" + item.endHour
                : item.endHour) +
              ":" +
              ((item.endMinute + "").length == 1
                ? "0" + "" + item.endMinute
                : item.endMinute);
          });

          console.log("出发", res.resultData);

          this.subsidyList = res.resultData;
        }
      });
    },

    welfareChowtimeListAddMet(item) {
      let params = {
        welfareChowtimeId: item.welfareChowtimeId,
        startHour: item.startTime.slice(0, 2),
        startMinute: item.startTime.slice(3, 5),
        endHour: item.finishTime.slice(0, 2),
        endMinute: item.finishTime.slice(3, 5),
        integral: item.integral,
      };

      welfareChowtimeListAdd(params).then((res) => {
        if (res.errorCode == null) {
          this.$message.success("保存成功！");
          this.welfareChowtimeListMet()
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.subsidy {
  .subsidy-header {
    font-size: 16px;
    font-weight: bold;
    margin: 20px 0;
  }

  .subsidy-block {
    .list {
      display: flex;
      align-items: center;
      margin-bottom: 20px;

      .title {
        font-size: 15px;
        margin-right: 20px;
      }

      .time {
      }

      .price {
        margin-left: 20px;
        display: flex;
        align-items: center;
        color: #808080;

        .integral {
          width: 100px;
        }

        /deep/ .el-input {
          margin-right: 10px;
        }
      }

      .button {
        display: flex;
        align-items: center;

        /deep/ .el-form-item__content {
          line-height: 0;
        }

        /deep/ .el-form-item__content {
          margin-left: 0 !important;
        }

        .title {
          background: #3da8f5;
          color: #fff;
          font-size: 16px;
          margin-right: 20px;
          border-radius: 5px;
          width: 80px;
          height: 35px;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
        }
      }
    }
  }
}
</style>